from sqlalchemy import create_engine

# HOSTNAME='127.0.0.1'
# PORT='3306'
# DATABASE = 'runoob1'
# USERNAME = 'yuan'
# PASSWORD = '123456'

# PyMySQL
# engine = create_engine('mysql+pymysql://scott:tiger@localhost/foo')
# DB_URI = "mysql+pymysql://(username):(password)@(host):(port)/(db)?charset=utf8".format(username=USERNAME,password=PASSWORD,host=HOSTNAME,db=DATABASE)

# engine = create_engine(DB_URI)

# 判断是否连接成功
# conn = engine.connect()
# result = conn.execute('select 1')
# print(result.fetchone())



# 连接数据库:
engine = create_engine("mysql+pymysql://yuan:123456@127.0.0.1:3306/runoob1",encoding="utf-8")

conn = engine.connect()
cur = conn.execute('select * from emp')
print("获取第一行数据")
print(cur.fetchone())
print("获取第2行数据")
print(cur.fetchmany(2))
print("获取所有数据")
print(cur.fetchall())
